package com.heima.admin.listener;

import com.alibaba.fastjson.JSON;
import com.heima.admin.service.WemediaNewsAutoScanService;
import com.heima.common.constants.message.NewsAutoScanConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @作者 itcast
 * @创建日期 2021/4/17 15:18
 **/
@Component
@Slf4j
public class WemediaNewsAutoListener {
    @Autowired
    WemediaNewsAutoScanService wemediaNewsAutoScanService;
    @KafkaListener(topics = {NewsAutoScanConstants.WM_NEWS_AUTO_SCAN_TOPIC})
    public void wemediaNewsAutoHandler(String message){
        log.info("收到 主题:{} 消息, 消息的内容为: {}",NewsAutoScanConstants.WM_NEWS_AUTO_SCAN_TOPIC,message);
        Map map = JSON.parseObject(message, Map.class);
        Integer newsId = (Integer)map.get("wmNewsId");
        log.info("自动审核开始 文章id ==>{}",newsId);
        wemediaNewsAutoScanService.autoScanByMediaNewsId(newsId);
    }
}
